package cn.hr.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import cn.hr.utils.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import cn.hr.dao.mapper.PostMapper;
import cn.hr.pojo.Post;
import cn.hr.service.PostService;

/**
 * 职位服务接口实现类
 *
 * @author MO
 */
@CacheConfig(cacheNames = "post")
@Scope("prototype")
@Service("postService")
public class PostServiceImpl implements PostService {
    @Resource
    private PostMapper postMapper;

    @Override
    public boolean insert(Post t) throws Exception {
        t.setCode("POST_CODE"+(postMapper.findMaxId()+1));
        return postMapper.insert(t)>0;
    }

    @Override
    public boolean update(Post t) throws Exception {
        return postMapper.update(t)>0;
    }

    @Override
    public boolean delete(Integer id) throws Exception {
        return postMapper.delete(id)>0;
    }

    @Override
    public Post get(Integer id) throws Exception {
        return postMapper.get(id);
    }

    @Override
    public PageInfo<Map> findListByCondition(Map m, int pageNo) throws Exception {
        PageHelper.startPage(pageNo, Constants.PAGESIZE);
        List<Map> list = postMapper.findListByCondition(m);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Long findCountByCondition(Map m) throws Exception {
        return null;
    }

    @Override
    public Post selectCode(Integer id) throws SQLException {
        return postMapper.selectCode(id);
    }

    @Override
    public String selectOFullName(Integer id) {
        return postMapper.selectOFullName(id);
    }
}
